#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
# GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
# Author: Shawn.Tan
# Date: 2025.10.28
#
# History: Initial Version 2025.10.28
#
#
from VectorTestSequence import VectorTestSequence
from gpgpu.EnvGPGPU import EnvGPGPU
from gpgpu.GenThreadGPGPU import GenThreadGPGPU


#  This test verifies that masked vector instructions do not set v0 as the
#  destination operand.
class MainSequence(VectorTestSequence):
    def __init__(self, aGenThread, aName=None):
        super().__init__(aGenThread, aName)

        self._mInstrList = (
            "VADD.VI##CALM",
            "VADD.VV##CALM",
            "VADD.VX##CALM",
            "VAND.VI##CALM",
            "VAND.VV##CALM",
            "VAND.VX##CALM",
            "VID.V##CALM",
            "VMAX.VV##CALM",
            "VMAX.VX##CALM",
            "VMAXU.VV##CALM",
            "VMAXU.VX##CALM",
            "VMIN.VV##CALM",
            "VMIN.VX##CALM",
            "VMINU.VV##CALM",
            "VMINU.VX##CALM",
            "VMSEQ.VI##CALM",
            "VMSEQ.VV##CALM",
            "VMSEQ.VX##CALM",
            "VMSGT.VI##CALM",
            "VMSGT.VX##CALM",
            "VMSGTU.VI##CALM",
            "VMSGTU.VX##CALM",
            "VMSLE.VI##CALM",
            "VMSLE.VV##CALM",
            "VMSLE.VX##CALM",
            "VMSLEU.VI##CALM",
            "VMSLEU.VV##CALM",
            "VMSLEU.VX##CALM",
            "VMSLT.VV##CALM",
            "VMSLT.VX##CALM",
            "VMSLTU.VV##CALM",
            "VMSLTU.VX##CALM",
            "VMSNE.VI##CALM",
            "VMSNE.VV##CALM",
            "VMSNE.VX##CALM",
            "VOR.VI##CALM",
            "VOR.VV##CALM",
            "VOR.VX##CALM",
            "VRSUB.VI##CALM",
            "VRSUB.VX##CALM",
            "VSADD.VI##CALM",
            "VSADD.VV##CALM",
            "VSADD.VX##CALM",
            "VSADDU.VI##CALM",
            "VSADDU.VV##CALM",
            "VSADDU.VX##CALM",
            "VSLIDEDOWN.VI##CALM",
            "VSLIDEDOWN.VX##CALM",
            "VSLL.VI##CALM",
            "VSLL.VV##CALM",
            "VSLL.VX##CALM",
            "VSMUL.VV##CALM",
            "VSMUL.VX##CALM",
            "VSRA.VI##CALM",
            "VSRA.VV##CALM",
            "VSRA.VX##CALM",
            "VSRL.VI##CALM",
            "VSRL.VV##CALM",
            "VSRL.VX##CALM",
            "VSSRA.VI##CALM",
            "VSSRA.VV##CALM",
            "VSSRA.VX##CALM",
            "VSSRL.VI##CALM",
            "VSSRL.VV##CALM",
            "VSSRL.VX##CALM",
            "VSSUB.VV##CALM",
            "VSSUB.VX##CALM",
            "VSSUBU.VV##CALM",
            "VSSUBU.VX##CALM",
            "VSUB.VV##CALM",
            "VSUB.VX##CALM",
            "VXOR.VI##CALM",
            "VXOR.VV##CALM",
            "VXOR.VX##CALM",
        )

    # Return the maximum number of test instructions to generate.
    def _getMaxInstructionCount(self):
        return 1000

    # Return a list of test instructions to randomly choose from.
    def _getInstructionList(self):
        return self._mInstrList

    # Verify additional aspects of the instruction generation and execution.
    #
    #  @param aInstr The name of the instruction.
    #  @param aInstrRecord A record of the generated instruction.
    def _performAdditionalVerification(self, aInstr, aInstrRecord):
        vm_val = aInstrRecord["Imms"]["vm"]
        vd_val = aInstrRecord["Dests"]["vd"]
        if (vm_val == 0) and (vd_val == 0):
            self.error("Instruction %s is masked with v0 as the destination register" % aInstr)


MainSequenceClass = MainSequence
GenThreadClass = GenThreadGPGPU
EnvClass = EnvGPGPU
